package inspur.entity;
/*
Cookie令牌对象

 */
import inspur.common.Sha1;

import javax.servlet.http.Cookie;
import java.util.Date;

public class CookieTokenObject {
    //cookie登陆令牌
    private Cookie userid;//
    private Cookie effectiveTime;//有效期
    private Cookie AuthorizedIP;//授权IP
    private Cookie sha1;//sha1指纹
    private Cookie password;//密码

    public CookieTokenObject() {
    }
    public CookieTokenObject(String userid, String authorizedIP,String password,int day) {
        int second=60*60*24*day;
        if (second<0){
            second=-1;
        }
        //userid
       Cookie cookie=new Cookie("userid",userid);
       cookie.setMaxAge(second);
       this.userid=cookie;
       //时间戳
        long effective;
        if (second<0){
           effective=new Date().getTime()/1000+60*60*24*1;
        }else {
            effective=new Date().getTime()/1000+second;
        }
        cookie=new Cookie("effectiveTime",effective+"");
        cookie.setMaxAge(second);
       this.effectiveTime=cookie;
       //授权IP
        cookie=new Cookie("AuthorizedIP",authorizedIP);
        cookie.setMaxAge(second);
        this.AuthorizedIP=cookie;
        //sha1指纹
        String sha1= Sha1.getSha1(userid+effective+authorizedIP+password);
        cookie=new Cookie("sha1",sha1);
        cookie.setMaxAge(second);
        this.sha1=cookie;
    }
    public Cookie getUserid() {
        return userid;
    }
    public void setUserid(Cookie userid) {
        this.userid = userid;
    }
    public Cookie getEffectiveTime() {
        return effectiveTime;
    }
    public void setEffectiveTime(Cookie effectiveTime) {
        this.effectiveTime = effectiveTime;
    }
    public Cookie getAuthorizedIP() {
        return AuthorizedIP;
    }
    public void setAuthorizedIP(Cookie authorizedIP) {
        AuthorizedIP = authorizedIP;
    }
    public Cookie getSha1() {
        return sha1;
    }
    public void setSha1(Cookie sha1) {
        this.sha1 = sha1;
    }
    public Cookie getPassword() {
        return password;
    }
    public void setPassword(Cookie password) {
        this.password = password;
    }
}
